import { defHttp } from '/@/utils/http/axios';

enum Api {
  LIST_URL = '/system/dept/tree',
  SAVE_URL = '/system/dept/create',
  UPDATE_URL = '/system/dept/update',
  DELETE_URL = '/system/dept/delete',
}

/**
 * 列表接口
 * @param params
 */
export const getDeptList = (params) => defHttp.get({ url: Api.LIST_URL, params });
/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const saveOrUpdateDept = (params, isUpdate) => {
  const url = isUpdate ? Api.UPDATE_URL : Api.SAVE_URL;
  return defHttp.post({ url: url, params });
};

/**
 * 删除部门
 */
export const deleteById = (params, reload) => {
  return defHttp.delete({ url: Api.DELETE_URL + `/${params.id}` }).then(() => {
    reload();
  });
};
